import 'package:get/get.dart';
import 'package:safetymonitor/app/core/env/env.dart';
import 'package:safetymonitor/app/core/http/network_manger.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/core/utils/log_util.dart';
import 'package:safetymonitor/app/core/utils/network.dart';
import 'package:safetymonitor/app/core/utils/user_manager.dart';
import 'package:safetymonitor/router/app_pages.dart';
class SplashControl extends GetxController {
  /// 失败提示
  final error = ''.obs;

  /// 初始化阿里云接口
  _init() async {
    // 初始化网络检测工具
    NetworkUtil.init();

    /// 延迟300毫秒,等待初始化完成
    await Future.delayed(const Duration(milliseconds: 300));

    if (DartDefines.appInstallChannel == AppInstallChannel.kaifa) {
      //内网ip
      // Interface.mainBaseUrl = 'http://10.1.31.118:30000';
      Interface.mainBaseUrl = 'http://203.56.192.202:30000';
      Interface.fileUrl = 'http://192.168.50.67:9090';
    } else if (DartDefines.appInstallChannel == AppInstallChannel.internal) {
      NetworkManager.switchIntranetAddress();
    } else if (DartDefines.appInstallChannel == AppInstallChannel.releaseservice) {

      AppLogger.log('当前网络环境为：${NetworkUtil.network.name}');

      /// 正式服有内网外网2种
      NetworkManager.netWorkInfo = NetworkManager.getNetWorkInfo();

      if(NetworkUtil.network != NetworkType.wifi) {
        NetworkManager.netWorkInfo = NetWorkInfo.extranet.name;
      }

      if(NetworkManager.netWorkInfo == NetWorkInfo.intranet.name) {
        NetworkManager.switchIntranetAddress();
      } else {
        NetworkManager.switchExtranetAddress();
      }
    }



    //本地 李映林
    // Interface.mainBaseUrl = 'http://172.18.254.149:30000';
    // Interface.fileUrl = 'http://192.168.50.67:9090';
    //测试环境
    // Interface.mainBaseUrl = 'http://203.56.192.202:30000';
    // Interface.fileUrl = 'http://192.168.50.67:9090';
    if (!UserManager.isLoggedIn) {
      // await Future.delayed(const Duration(seconds: 1));
      Get.offAndToNamed(Routes.authLogin);
    } else {
      Get.offAndToNamed(Routes.home);
    }

  }

  @override
  void onInit() {
    super.onInit();
    _init();
  }


}
